package com.sixsixsixstudy.twopc;

import com.sixsixsixstudy.common.constant.UrlConstant;
import com.sixsixsixstudy.common.utils.HttpUtil;
import lombok.Data;
import org.springframework.web.client.RestTemplate;

/**
 * 事务管理者
 *
 * @author SUN
 * @date 2023/4/1
 */
public class TransactionManager {
    
    private final String server;
    
    private final int port;
    
    public TransactionManager(String server, int port) {
        this.server = server;
        this.port = port;
    }
    
    /**
     * 开启事务
     */
    public void start() {
        prepare();
    }
    
    public void register(ResourceManager resourceManager) {
       HttpUtil.post(String.format("http://%s:%s/%s", server, port, UrlConstant.REGISTER), resourceManager,
                Boolean.class);
        
    }
    
    private void prepare() {
        HttpUtil.post(String.format("http://%s:%s/%s", server, port, UrlConstant.PREPARE), null,
                Boolean.class);
    }
    
    
}
